package com.facishare.open.aop;

import com.facishare.open.ajax.code.AjaxCode;
import com.facishare.open.common.result.exception.BizException;
import com.facishare.open.context.SysContext;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;

import javax.servlet.http.HttpSession;

/**
 * Created by linchf on 2016/7/25.
 */

@Slf4j
public class AuthAspect {

    public Object around(ProceedingJoinPoint point) throws Throwable {

        HttpSession session = SysContext.getSession();
        if(session.getAttribute("user") == null ) {
            throw new BizException(AjaxCode.USER_NOT_LOGIN,"没有登陆,无权限");
        }
        try {
            return point.proceed();
        }finally {
            log.info("业务完成");
        }
    }

    public void before() throws Throwable {
        HttpSession session = SysContext.getSession();
        if(session.getAttribute("user") == null ) {
            throw new BizException(AjaxCode.USER_NOT_LOGIN,"没有登陆,无权限");
        }
    }
}
